from allpairspy import AllPairs

from api_py.enums.cookie import Cookie
from api_py.generate_case.template import template_case
from api_py.utils.file_sys import write_json

# TODO 如果修改了一个用户名不合法的督导，是否算缺陷

username = [
    {"value": "updateSuper", "description": "用户名存在"},
    {"value": "notExist", "description": "用户名不存在"},
]

password = [
    {"value": "addSuper", "description": "合法密码"},
    {"value": "aaaa", "description": "长度小于6的密码"},
    {"value": "aaaaaaaaaaaaaaaaaaaaaaaaaa", "description": "长度大于20的密码"},
]

name = [
    {"value": "newName", "description": "名字合法"},
    {"value": "new_Name", "description": "名字存在非法字符"},
    {"value": "newNamenewNamenewName", "description": "名字长度大于15"},
    {"value": "newNamene###NamenewName", "description": "名字长度大于15且存在非法字符"},
]

phoneNumber = [
    {"value": "11900000000", "description": "电话合法且唯一"},
    {"value": "15900000000", "description": "电话合法但不唯一"},
    {"value": "123", "description": "电话号码非法"},
]

idNumber = [
    {"value": "350781196403074025", "description": "身份证合法"},
    {"value": "111181196403074025", "description": "身份证长度合法"},
    {"value": "AAAA", "description": "身份证完全非法"},
]

department = [
    {"value": "华东师范大学", "description": "所在部门"},
    {"value": "华东师###@@@@范大学", "description": "所在部门存在非法字符"},
]

title = [
    {"value": 3213, "description": "合法职称"},
]

qualification = [
    {"value": "三级", "description": "三级资质"},
    {"value": "二级", "description": "二级资质"},
    {"value": "一级", "description": "一级资质"},
    {"value": "abc", "description": "资质非法"},
]

qualificationCode = [
    {"value": "", "description": "资质编号为空"},
    {"value": "12345", "description": "合法资质编号"},
]

email = [
    {"value": "a@qq.com", "description": "合法邮箱"},
    {"value": "abc", "description": "非法邮箱"},
]

cookies = [
    {"value": Cookie.ADMIN_COOKIE.value, "description": "管理员登录"},
    {"value": Cookie.SUPERVISOR_COOKIE.value, "description": "督导登录"},
    {"value": Cookie.COUNSELOR_COOKIE.value, "description": "咨询师登录"},
    {"value": Cookie.WEIXIN_COOKIE.value, "description": "微信访客登录"},
    {"value": Cookie.NULL_COOKIE.value, "description": "未登录"},
    {"value": Cookie.ERROR_COOKIE.value, "description": "其他Cookie"},
]

body = [
    {"value": "addSuper", "description": "用户名合法"},
    {"value": "addSuper", "description": "合法密码"},
    {"value": "newName", "description": "名字合法"},
    {"value": "11900000000", "description": "电话合法且唯一"},
    {"value": "350781196403074025", "description": "身份证合法"},
    {"value": "华东师范大学", "description": "所在部门"},
    {"value": 3213, "description": "合法职称"},
    {"value": "三级", "description": "三级资质"},
    {"value": "12345", "description": "合法资质编号"},
    {"value": "a@qq.com", "description": "合法邮箱"},
]


def case11_user_ms_supervisor(api_type):
    json_result = {}
    parameters = [username, password, name, phoneNumber, idNumber, department, title, email, qualification, qualificationCode]
    i = 0

    # 检测数据格式用例
    for pairs in AllPairs(parameters):
        case = template_case()
        request = case["request"]

        # 设置请求体参数
        request["body"]["username"] = pairs[0]
        request["body"]["password"] = pairs[1]
        request["body"]["name"] = pairs[2]
        request["body"]["phoneNumber"] = pairs[3]
        request["body"]["idNumber"] = pairs[4]
        request["body"]["department"] = pairs[5]
        request["body"]["title"] = pairs[6]
        request["body"]["email"] = pairs[7]
        request["body"]["qualification"] = pairs[8]
        request["body"]["qualificationCode"] = pairs[9]
        # 设置请求头cookie
        request["headers"]["Cookie"] = cookies[0]

        json_result[i] = case
        i += 1

    for cookie in cookies:
        case = template_case()
        request = case["request"]
        # 设置请求体参数
        request["body"]["username"] = body[0]
        request["body"]["password"] = body[1]
        request["body"]["name"] = body[2]
        request["body"]["phoneNumber"] = body[3]
        request["body"]["idNumber"] = body[4]
        request["body"]["department"] = body[5]
        request["body"]["title"] = body[6]
        request["body"]["email"] = body[7]
        request["body"]["qualification"] = body[8]
        request["body"]["qualificationCode"] = body[9]
        # 设置请求头cookie
        request["headers"]["Cookie"] = cookie

        json_result[i] = case
        i += 1

    write_json(api_type.value[0]["file_name"], json_result)
